<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>    
    <title>Counter Strike Live Chat</title>
    <style type="text/css">
        #txtarea
        {
            height: 628px;
            width: 100%;
        }
        #input
        {
            width: 100%;
        }
    </style>
</head>
<body>            
    Counter Strike Live Chat<br />
    <textarea id="txtarea"></textarea>
    <br />
    <input id="input" type="text"/>
    <script type="text/javascript" language="javascript">        
        var input = document.getElementById('input');
        var txtarea = document.getElementById('txtarea');
        setInterval("tick()", 1000);
        input.onkeydown = function onkeydown(evt) {        
            var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
            if (keyCode == 13) {
                Click();
            }
        }        
        function Click() {
            if (input.value != "") {
                ajax("/?send=" + input.value + "&r=" + Math.random(), null, reply);
                input.value = "";
            }
        }
        function reply(text) {
            txtarea.value += text+"\n";
            txtarea.scrollTop = txtarea.scrollHeight;
        }
        function tick() {
            ajax("/?get&r=" + Math.random(), null, onrecv);
        }
        function onrecv(text) {

            txtarea.value += text;
            txtarea.scrollTop = txtarea.scrollHeight;
        }
        
        function ajax(url, vars, callbackFunction) {
            var request = getXmlHttp();
            request.open("GET", url, true);
            request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");

            request.onreadystatechange = function() {
                var done = 4, ok = 200;
                if (request.readyState == done && request.status == ok) {
                    if (request.responseText && callbackFunction!=null) {
                       callbackFunction(request.responseText);
                    }
                }
            };
            request.send(null);
        }
        function getXmlHttp() {
            var xmlhttp;
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp = false;
                }
            }
            if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                xmlhttp = new XMLHttpRequest();
            }
            return xmlhttp;
        }
    </script>

    <form action="/" method="get"><input name="q" type="text" /><input type="submit" value="Search" /></form>
</body>
</html>